<style lang="less">
  .card_style {
    height: 100%;
    width: 100%;
    overflow: hidden;
    .ivu-card-body {
      padding: 0px;
    }
  }
  .page_style {
    margin-top: 10px;
    text-align: right;
  }
  .bench_search {
    margin-bottom: 10px;
  }
  .nopadding .ivu-table-cell {
    padding: 0px 0px;
  }
  .item1{
    height: 42px;
    line-height: 40px;
  }
  .new-btn-sty {
    margin-right: 5px;
    color: #fff;
    background-color: #235CA7;
    border-color: #235CA7;
    font-weight: 500;
  }
</style>

<template>
  <Card class="card_style" :bordered="false" :dis-hover="true">
    <Row class="bench_search">
      <Col span="6">
        <span>事项类型：</span>
        <Select v-model="searchInfo.item_type" filterable transfer="" style="width: 75%;" @on-change="changeItem1(searchInfo.item_type)">
          <Option :value="item.id" v-for="item in treelist" v-bind:key="item.id">{{item.type_name}}</Option>
        </Select>
      </Col>
      <Col span="6">
        <span>事项名称：</span>
        <Select v-model="searchInfo.item_id" filterable transfer="" style="width: 75%;">
          <Option :value="item.id" v-for="item in eventListSQ" v-bind:key="item.id">{{item.text}}</Option>
        </Select>
      </Col>
      <Button class="new-btn-sty" @click="searchData" style="margin-right:10px"><Icon type="ios-search" /> 搜索</Button>
      <Button class="new-btn-sty" @click="editNotice({})"><Icon type="md-add" /> 创建</Button>
      <Modal v-model="modalEdit" title="代理信息" width="700" cancel-text="关闭"
        @on-ok="ok111(paramData2)" @on-cancel="modalEdit=false" ok-text="确定">
        <Form :model="paramData2" >
          <Row class="item1">
            <Col span="5" style="text-align: right" class="">代理人姓名:</Col>
            <Col span="12" offset="1">
              <Input v-model="paramData2.agent_name"></Input>
            </Col>
          </Row>
          <Row class="item1" style="height:auto;line-height:auto">
            <Col span="5" style="text-align: right" class="">代理人联系方式:</Col>
            <Col span="12" offset="1">
              <Input v-model="paramData2.agent_phone"></Input>
            </Col>
          </Row>
          <Row class="item1" style="height:auto;line-height:auto">
            <Col span="5" style="text-align: right" class="">办理人姓名:</Col>
            <Col span="12" offset="1">
              <Input v-model="paramData2.handler_name"></Input>
            </Col>
          </Row>
          <Row class="item1">
            <Col span="5" style="text-align: right" class="">办理人联系方式:</Col>
            <Col span="12" offset="1">
              <Input v-model="paramData2.handler_phone"></Input>
            </Col>
          </Row>
          <Row  class="item1">
            <Col span="5" style="text-align: right" class="">事项类型:</Col>
            <Col span="12" offset="1">
              <Select v-model="paramData2.item_type" filterable transfer="" @on-change="changeItem1(paramData2.item_type)">
                <Option :value="item.id" v-for="item in treelist" v-bind:key="item.id">{{item.type_name}}</Option>
              </Select>
            </Col>
          </Row>
          <Row  class="item1">
            <Col span="5" style="text-align: right" class="">事项名称:</Col>
            <Col span="12" offset="1">
              <Select v-model="paramData2.item_id" filterable transfer="">
                <Option :value="item.id" v-for="item in eventListSQ" v-bind:key="item.id">{{item.text}}</Option>
              </Select>
            </Col>
          </Row>
          <Row  class="item1">
            <Col span="5" style="text-align: right" class="">代理时间:</Col>
            <Col span="12" offset="1">
              <DatePicker type="datetime" format="yyyy-MM-dd HH:mm" v-model="paramData2.agent_time" placeholder="代理时间" style="width: 100%"></DatePicker>
            </Col>
          </Row>
        </Form>
      </Modal>
    </Row>
    <Table border :columns="columns1" :data="datalist"></Table>
    <Row v-if="loadData == true">
      <Col class="demo-spin-col" span="8" offset="8">
        <Spin fix>
          <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
          <div>数据正在加载</div>
        </Spin>
      </Col>
    </Row>
    <Page :total="totalnum" :current="currentPageNo" :page-size="currentPageSize" @on-change="matterPage" class="page_style" show-sizer @on-page-size-change="SXsize"/>
<!--    <Page :total="totalnum" :current="currentPageNo" :page-size="currentPageSize" @on-change="init(param)" class="page_style"/>-->
  </Card>
</template>

<script>
import {
  findinfomationList,
  saveinfomation,
  setSituationState,
  date0str,
  treelist,
  eventlist
} from '@/api/eventlist'
// import { releaseNoticeList } from '@/api/mainv3'

export default {
  name: 'message',
  data () {
    return {
      loadData: true,
      treelist: [],
      eventListSC: [],
      eventListSQ: [],
      showNotice: false,
      modalEdit: false,
      params: { pageNo: '', pageSize: '' },
      searchInfo: { item_type: '', item_id: '' },
      paramData: {},
      // 修改或添加新通知公告时使用
      paramData2: {},
      totalnum: 0,
      currentPageNo: 1,
      currentPageSize: 10,
      columns1: [
        { title: '序号', type: 'index', width: 70, align: 'center' },
        { title: '代办人姓名', key: 'agent_name', width: 100, align: 'center' },
        { title: '代办人联系方式', key: 'agent_phone', width: 150, align: 'center' },
        { title: '办理人姓名', key: 'handler_name', width: 100, align: 'center' },
        { title: '办理人联系方式', key: 'handler_phone', width: 150, align: 'center' },
        {
          title: '代办事项',
          key: 'QL_NAME',
          width: 300,
          align: 'center'
        },
        { title: '代办时间', key: 'agent_time', width: 200, align: 'center' },
        {
          title: '操作',
          key: 'action',
          align: 'center',
          className: 'nopadding',
          minWidth: 150,
          render: (h, params) => {
            let temp = []
            temp.push(
              h('Button', {
                props: { type: 'primary', size: 'small' },
                style: { marginRight: '5px', backgroundColor: '#598ED1', borderColor: '#598ED1' },
                on: {
                  click: () => {
                    this.editNotice(params.row)
                  }
                }
              }, '编辑')
            )
            return h('div', temp)
          }
        }
      ],
      datalist: []
    }
  },
  computed: {
    companyCode () {
      return this.$store.state.user.severUserInfo.company_code
    }
  },
  methods: {
    // 事项类型列表，页面搜索栏使用
    getTreeList () {
      treelist({}).then(res => {
        if (res.data.errcode === 0) {
          this.treelist = res.data.data
          this.treelist.unshift({ id: '', type_name: '全部' })
          this.$forceUpdate()
        } else {
          this.$Notice.error({ title: '获取信息失败', desc: '查询事项类型列表失败' })
        }
      })
    },
    changeItem1 (item_type) {
      let that = this
      that.eventListSQ = []
      that.eventListSC.forEach(function (temp1, index) {
        if (temp1.org_code === item_type) {
          that.eventListSQ.push(temp1)
        }
      })
      that.eventListSQ.unshift({ id: 0, text: '全部' })
    },
    // 已有事项列表，页面搜索栏使用
    getItemList () {
      eventlist({}).then(res => {
        console.log(res)
        if (res.data.errcode === 0) {
          this.eventListSC = res.data.data
          this.eventListSC.unshift({ id: 0, text: '全部' })
          this.$forceUpdate()
        } else {
          this.$Notice.error({ title: '获取信息失败', desc: '查询事项劣列表失败' })
        }
      })
    },
    // 查询代理信息接口
    init (param) {
      if (this.companyCode) {
        param.pageNo = this.currentPageNo
        param.pageSize = this.currentPageSize
        findinfomationList(param).then(res => {
          if (res.data.errcode === 0) {
            this.datalist = res.data.data.results
            this.totalnum = res.data.data.totalRecord
            this.loadData = false
          } else {
            this.loadData = true
            this.$Notice.error({ title: '获取代理人信息列表失败', desc: res.data.errmsg })
          }
        })
      }
    },
    SXsize (pageSize) {
      this.currentPageSize = pageSize
      this.init(this.params)
    },
    matterPage (pageNo) {
      this.currentPageNo = pageNo
      this.init(this.params)
    },
    ok111 (param) {
      let agent_time = new Date()
      if (agent_time) {
        agent_time = date0str(param.agent_time)
        console.log(agent_time, '22222')
      } else {
        agent_time = null
      }
      param.agent_time = agent_time
      console.log(param.agent_time, '333333')
      saveinfomation(param).then(res => {
        if (res.data.errcode === 0) {
          this.init(this.params)
          this.$Notice.success({ title: '成功', desc: '' })
        } else {
          this.$Notice.error({ title: '失败', desc: res.data.errmsg })
        }
      })
    },
    showInfo (item) {
      this.showNotice = true
      this.paramData.title = item.title
      this.paramData.content = item.contents
      this.paramData.sort = item.sort
      this.paramData.release_time = item.release_time
    },
    editNotice (item) {
      this.modalEdit = true
      let agent_time = new Date()
      if (item.agent_time) {
        agent_time = date0str(item.agent_time)
      } else {
        agent_time = null
      }
      console.log(item.agent_time, 'aaaa')
      this.paramData2.id = item.id || null
      this.paramData2.agent_name = item.agent_name || ''
      this.paramData2.agent_phone = item.agent_phone || ''
      this.paramData2.handler_name = item.handler_name || ''
      this.paramData2.handler_phone = item.handler_phone || ''
      this.paramData2.item_type = item.ORG_CODE || ''
      this.changeItem1(this.paramData2.item_type)
      this.paramData2.item_id = item.ITEM_CODE || ''
      this.paramData2.agent_time = agent_time || null
    },
    searchData () {
      let params = {
        ITEM_CODE: this.searchInfo.item_id,
        ORG_CODE: this.searchInfo.item_type
      }
      this.currentPageNo = 1
      this.init(params)
    },
    change (pageNo) {
      this.currentPageNo = pageNo
      let params = {
        ITEM_CODE: this.searchInfo.item_id,
        ORG_CODE: this.searchInfo.item_type
      }
      this.init(params)
    },
    // 发布or撤销,state==='1'时表示发布通知，state==='0'时表示撤销通知
    setNoticeState (item, state) {
      let msg = state === '1' ? '确定已检查吗！' : '确认未检查吗！'
      var param = { id: item.id, state: state }
      if (confirm(msg)) {
        setSituationState(param).then(res => {
          if (res.data.errcode === 0) {
            this.init(this.params)
            return
          }
          this.$Notice.error({ title: '失败', desc: res.errmsg })
        })
      }
    }
  },
  mounted () {
    this.init(this.params)
    this.getTreeList()
    this.getItemList()
  }
}
</script>
